import { dealDataExcept, dealDataRide } from "@/utils/common";
import { goodsCodeRend, goodsNameRend } from "@/utils/tableColumns";

export function useColumns() {
  const getVarianceNum = row => {
    return (
      dealDataExcept(dealDataRide(row.avgBuyPrice, row.scrapNum || 0)) || "--"
    );
  };

  // 库存盘点
  const kcpdColumns: TableColumnList = [
    {
      label: "商品名称/规格名称",
      prop: "businessDate",
      minWidth: 180,
      cellRenderer: goodsNameRend
    },
    {
      label: "商品编码/规格编码",
      prop: "atCount",
      minWidth: 180,
      cellRenderer: goodsCodeRend
    },
    {
      label: "商品条码",
      prop: "barCode",
      minWidth: 120,
      formatter: ({ barCode }) => barCode || "--"
    },
    {
      label: "商品均价",
      prop: "atCount",
      minWidth: 110,
      formatter: ({ avgBuyPrice }) => dealDataExcept(avgBuyPrice)
    },
    {
      label: "报废数量",
      prop: "scrapNum",
      minWidth: 130,
      cellRenderer: ({ row }) => (
        <el-input-number
          min={0}
          step={1}
          step-strictly
          v-model={row.scrapNum}
          placeholder="请输入"
          style="width: 100%"
        />
      )
    },
    {
      label: "报废总额",
      prop: "varianceNum",
      minWidth: 110,
      formatter: row => getVarianceNum(row)
    },
    {
      label: "操作",
      prop: "varianceNum",
      minWidth: 70,
      slot: "operation"
    }
  ];

  return {
    kcpdColumns
  };
}
